Ext.define('DCApp.store.Navigation', {
    extend: 'Ext.data.TreeStore',
    alias: 'store.navigation',

    constructor: function(config) {
        var me = this,
            queryParams = Ext.Object.fromQueryString(location.search),
            charts = ('charts' in queryParams) && !/0|false|no/i.test(queryParams.charts);

        me.callParent([Ext.apply({
            root: {
                text: '全部',
                id: 'all',
                expanded: true,
                children:  me.getNavItems()
            }
        }, config)]);
    },

    addIconClasses: function (items) {
        for (var item, i = items.length; i-- > 0; ) {
            item = items[i];

            if (!('iconCls' in item)) {
                item.iconCls = 'icon-' + item.id;
            }

            if (!('glyph' in item)) {
                // sets the font-family
                item.glyph = '32@Sencha-Examples';
            }

            if (item.children) {
                this.addIconClasses(item.children);
            }
        }

        return items;
    },


    getNavItems: function() {
    	var menus=[
            {
                id: 'dg_zw',
                expanded: true,
                text: 'SimData仿真',
                leaf: false,
                description: '前端数据交互仿真',
                children: [
                    {id: 'reliclist', text: '藏品', leaf: true },
	                {id: 'doclist',idd:'docdetail', text: '文稿', leaf: true },
                    {id: 'imagelist', text: '影像', leaf: true },
                    {id: 'CeAttachmentlist', text: '附件', leaf: true }
                ]
            }, 
            {
                text: 'SpringSide QuickStart',
                id: 'sz',
                expanded: true,
                description: '与SpringSide的整合',
                children: [
                    {id: 'Userlist', text: '用户', leaf: true },
                    {id: 'Tasklist', text: '任务', leaf: true }
                ]
            }, 
            {
                text: 'RoadMap',
                id: 'sz_xx',
                expanded: true,
                description: '新特性路线图',
                children: [
                    {id: 'emap', text: 'WebSocket示例', leaf: true }
                ]
            }
        ];
    	var cfg_menus=DCApp.Cfg.usrInfo.get('menu');
    	var perms = DCApp.Cfg.usrInfo.get('perms');
    	DCApp.Cfg.bView = (perms=='*:view');
    	//用户配置菜单为空显示全部
    	if(!cfg_menus || $.trim(cfg_menus)=='')
    		return this.addIconClasses(menus);
    	//只显示配置菜单项
    	var user_menus=[];
    	var ums=cfg_menus.split(';');
    	for(var i=0; i<menus.length; i++){
    		var mid = menus[i].id;
    		var bfind=false;
    		for(var j=0;j<ums.length; j++){
    			if(ums[j]==mid){
    				bfind=true;
    				break;
    			}
    		}
    		if(bfind){
    			user_menus[user_menus.length]=menus[i];
    		}
    	}
    	return this.addIconClasses(user_menus);
    }
});
